import json
import uvicorn
from fastapi import FastAPI
from fastapi.responses import FileResponse
from fastapi.middleware.cors import CORSMiddleware
import os
import sys
import warnings
# 添加项目根目录到Python路径
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from app.config.config import HOST, PORT, RELOAD
from app.utils.lifespan_manager import lifespan
from app.api import websocket, http_routes

# 创建FastAPI应用
app = FastAPI(title="AI WebSocket Server", lifespan=lifespan)
# 忽略 websockets 库的弃用警告

warnings.filterwarnings("ignore", category=DeprecationWarning, module="websockets")
warnings.filterwarnings("ignore", category=DeprecationWarning, module="uvicorn")
# 添加CORS中间件
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# 包含路由
app.include_router(websocket.router)
app.include_router(http_routes.router)

# 提供client.html文件
@app.get("/")
async def get_client():
    
    return {"message": "运行正常!"}

if __name__ == "__main__":
    # 启动服务器
    uvicorn.run(
        "app.main:app",
        host=HOST,
        port=PORT,
        reload=RELOAD
    )